package utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;


import java.net.*;


public class ReaderFactory {
    public static StringBuffer readUrlData(URL u, String enc)
    throws IOException{
    	InputStream is = u.openStream();
    	InputStreamReader is2 = new InputStreamReader(is,enc);
    	    StringBuffer data = new StringBuffer(1000);
            BufferedReader reader = new BufferedReader(is2);
            char[] buf = new char[1024];
            int numRead=0;
            while((numRead=reader.read(buf)) != -1){
                String readData = String.valueOf(buf, 0, numRead);
                data.append(readData);
                buf = new char[1024];
            }
            reader.close();
        return data;
    }
   public static String URLConnectionRead(URL u) throws Exception {
            
            URLConnection yc = u.openConnection();
    	    StringBuffer data = new StringBuffer(1000);
            BufferedReader in = new BufferedReader(
                                    new InputStreamReader(
                                    yc.getInputStream()));
            String inputLine;

            while ((inputLine = in.readLine()) != null) 
                data.append(inputLine);
            in.close();
            return data.toString();
        }
}

